home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 205 / docs / more.doc / text0000.txt < prev   
Encoding:
Text File  |  1989-02-16  |  7.2 KB  |  166 lines

  1. (Whatever is described below was checked for a gulam version
  2. which identifies itself as:
  3.  
  4.     beta test version 1.03.04.05 121887 of
  5.     yet another shell for AtariST/TOS
  6.  
  7. Your mileage may vary!!)
  8.  
  9.    As you may not know, a very popular Gulam shell (many thanks to
  10. Prabhaker Mateti and Jwahar R. Bammi). includes quite powerful facility
  11. to invoke gulam services from a program started from gulam.  In contrast
  12. to many others shells floating aroung this is not done by executing
  13. the next incarnation of gulam. Instead there are provided two pointers
  14. which provide execution 'hooks' for all gulam commands.  A bright sight
  15. is that this approach does not take any extra memory and a start-up
  16. time is negligible. A dark side is that documentation describing this
  17. facility is either misleading or plainly wrong.  (As an aside - this
  18. is, alas, not the only place in documentation requiring touch-up.
  19. For this version, gulam.hlp, for example, does not correspond very well
  20. tp reality).
  21.  
  22.    This note is a kind of erratum, which, hopefuly, will help to clarify
  23. an ensuing confusion, which seems to be quite widespread.
  24.  
  25.    When you are running Gulam a TOS variable '_shell_p', at 0x4f6,
  26. contains an address of a location named 'togu_', which is the last entry
  27. in a 16 byte long table. The format of the table is (this is mostly quoted
  28. from the documentation):
  29.  
  30.                .long   0x86420135        / our magic number (4 bytes)
  31.                jmp     getlineviaue_     / 0x4ef9,address   (6 bytes)
  32.        togu_:  jmp     callgulam_        / 0x4ef9,address   (6 bytes)
  33.  
  34. It clearly follows from that that magic number is located 10 bytes before
  35. 'togu_' and not, the documentation suggested, 12.  What's more, the magic 
  36. number should be equal *(long *)(*(char **)0x4f6 - 10), instead of a
  37. given *((long *)0x46fL - 12L), which will produce a value from an address
  38. way off.  On the top of it, an actual magic number in my copy of Gulam
  39. is not like the documented but it equals 0x00420135.  Use Gulam 'peekw'
  40. to check what you got. To be on a safe side, until the matter
  41. is fully clarified, I am using only a lower half of the magic number,
  42. which seems to be correct; i.e. short_magic = *(short *)(*(char **)0x4f6-8).
  43.  
  44.   Two other items in the table are entry points to two functions
  45. 'getlineviaue' and 'callgulam'.  The information given in the documentation
  46. about them is mostly correct, with a similar mix-up in a calculation
  47. of an address of entry to 'getlineviaue', like the one described above.
  48. Also, strictly speaking, 'getlinevalue' does not return anything, since
  49. it is declared as 'void'. As a side effect it modifies a contents of
  50. a user supplied buffer, copying there a contents of a command line. It
  51. would be probably more convenient if, instead of being void, it would return
  52. something useful, say a number of copied characters, but it doesn't,
  53. so we may have to live with that.  Just to make our life more
  54. interesting, the other function, 'callgulam', returns 'int' - the return
  55. status of an executed command.  This makes wonders to types of your
  56. pointers.  See the supplied program example for to see how to cast.
  57. All of this to ensure that your C-compiler will not get totally lost.
  58. If you have a compiler which accepts the stuff in a form from an original
  59. docs - replace your compiler. Fast!
  60. (As an aside - all this pointer play would be easier in assembler, 
  61. if you feel so inclined).
  62.  
  63.   While experimenting whith the program example try the following.
  64. Call 'ue' on some file, position cursor somewher down the text and
  65. stop editor with ^Z. Try some other commands and upon return to Gulam
  66. type 'fg'.  Repeat experiment stopping the editor in Gulam and typing
  67. 'fg' from the demo program prompt. Don't you think that this is a nice
  68. way to run editor for your, say, Lisp interpreter?
  69.  
  70.   Some things are still missing. One cannot tell 'ue', on a command
  71. line, to load a file and go to the line 247.  Or there is a way and I
  72. am simply not aware of it?  And I know of no way to grab a result of
  73. a command, stuff it into a variable and use it for a test of conditional
  74. script execution.  Oh well, maybe in some future release...
  75.  
  76.   Two other, non-interactive, ways of calling Gulam are also mentioned
  77. in docs.  I did not try 'Pexec method', but attempts to execute 
  78. gulam as a program with arguments, as described, produced only
  79. nonsensical error messages about 'invalid regexp' and error number -33.
  80. Can anybody shed some light on that matter?
  81.  
  82.  
  83.    Michal Jaegermann
  84.    Myrias Research Corporation
  85.    Edmonton, Alberta, CANADA
  86.    ...alberta!myrias!mj
  87.    (or you may try mj@myrias.UUCP)
  88.  
  89. ------------------------------------------------------------------------------
  90.  
  91. /* 
  92. * A demo program to show a usage of Gulam 'hooks' - call from
  93. * Gulam shell!  When asked, try different gulam commands, ue
  94. * in particular.
  95. *
  96. * A numbers of pointers floating around is a little bit higher
  97. * than necessary, but we will waiste some memore for the sake
  98. * of clarity.
  99. *
  100. * Michal Jaegermann, October 1988
  101. */
  102.  
  103. #include <stdio.h>
  104. #include <osbind.h>
  105. #include <string.h>
  106. #define  SHELLP         ((char **) 0x04f6L)
  107. #define  G_MAGIC        0x0135
  108.  
  109. main()
  110. {
  111.        long save_ssp;
  112.        short sh_magic;
  113.        char buf[258];
  114.        char *tgptr;            /* storage for togu_         */
  115.        /* if you really would like to have it right, then   */
  116.        /* tgptr should be a pointer to void -             */
  117.        /* a bit of overkill on ST :-)                */
  118.        
  119.                       
  120.        int  (* cgp)();         /* pointer to callgulam()    */
  121.                                /* also contains togu_, but  */
  122.                                /* a type is different       */
  123.        void (* glp)();         /* pointer to getlineviaue() */
  124.  
  125.        fprintf(stderr, "Welcome to callgulam demo.\n");
  126.        save_ssp = Super(0L);
  127.        tgptr = *SHELLP;
  128.        Super(save_ssp);
  129.  
  130.        if (G_MAGIC != (sh_magic = *((short *)(tgptr - 8)))) {
  131.                fprintf (stderr, "wrong magic value %x\n", sh_magic);
  132.                exit (1);
  133.        }
  134.  
  135.        cgp = *((int (*)()) tgptr);
  136.        glp = *((void (*)()) (tgptr - 6));
  137.        (* cgp)("echo 'test of Gulam'");
  138.        (* cgp)("echo 'executing ls -l'");
  139.        (* cgp)("ls -l");
  140.        (* cgp)("echo '-----------------'");
  141.        (* cgp)("ls -R -t a:\\ ");
  142.        (* cgp)("echo ' '");
  143.        (* cgp)("echo ' '");
  144.        (* cgp)("set tmp_old_prompt $prompt");
  145.        (* cgp)("set prompt 'At your service, Sir!'");
  146.                /* change a gender if a need will arise */
  147.        (* cgp)("echo 'Awaiting your commands!!'");
  148.        /* the following loop will cycle until it will get an empty line */
  149.        while ((* glp)(buf), putchar('\n'), 0 != strlen(buf)) {
  150.                                        /* the new line not supplied */
  151.                                        /* by Gulam - DIY, mate       */
  152.                (* cgp)(buf);
  153.        }
  154.        (* cgp)("set prompt $tmp_old_prompt");
  155.        (* cgp)("unset tmp_old_prompt");
  156.        fprintf (stderr,"\nNice talking to you, see you later.\n");
  157.        exit(0);
  158. }
  159. /* -----------------/ that is all for today /--------------------- */
  160.  
  161. -- 
  162.     Michal Jaegermann
  163.     Myrias Research Corporation
  164.     Edmonton, Alberta, CANADA
  165.     ...{ihnp4, ubc-vision}!elberta!myrias!mj
  166.